﻿using ClassLibraryLab3;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab5_2_
{
    public partial class Form1 : Form
    {
        public List<Cargo> productList1 = new List<Cargo>();
        public List<Agriculture> productList2 = new List<Agriculture>();
        public List<LightAircraft> productList3 = new List<LightAircraft>();
        public List<Screw> productList4 = new List<Screw>();
        public List<Transcontinental> productList5 = new List<Transcontinental>();
        public List<Personal> productList6 = new List<Personal>();

        int[] CountPassengers = new int[10];

        List<String> name = new List<String>();
        List<Decimal> structure = new List<Decimal>();
        List<Decimal> size = new List<Decimal>();
        List<String> maneuverability = new List<String>();
        List<String> power = new List<String>();
        List<String> protection = new List<String>();
        
        Form2 f = new Form2();
        


        public Creator[] creators = new Creator[10];

        public Form1()
        {
            InitializeComponent();
        }

        public void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("Cargos");
            comboBox1.Items.Add("Agricultures");
            comboBox1.Items.Add("LightAircrafts");
            comboBox1.Items.Add("Screws");
            comboBox1.Items.Add("Transcontinentals");
            comboBox1.Items.Add("Personals");

        }

        public void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            

            for (int i = 0; i < 7; i++)
            {
                CountPassengers[i] = 0;
            }
        
            int[] product = new int[6];

            creators[0] = new CreatorService();

            foreach (Creator cr in creators)
            {
                if (cr is CreatorService)
                {
                    try
                    {
                    productList1.Add(cr.FactoryMethod3("Ан-24", 4, 8, "Низкая", "Высокая", "Высокая"));
                    product[0]++;
                    productList2.Add(cr.FactoryMethod4("Ан-2", 1, 2, "Высокая", "Низкая", 43000));
                    product[1]++;
                    productList3.Add(cr.FactoryMethod5("Peregrine SL", 1, 2, "Высокая", "Низкая", 282, 350));
                    product[2]++;
                    productList4.Add(cr.FactoryMethod7("Цикада 4", 2, 4, "Низкая", 300));
                    product[3]++;
                    productList5.Add(cr.FactoryMethod8("A-380", 4, 853, "Высокая", 15400));
                    product[4]++;
                    productList5.Add(cr.FactoryMethod8("Боинг-777", 2, 550, "Высокая", 17500));
                    product[4]++;
                    productList6.Add(cr.FactoryMethod9("Falcon 900", 2, 8, "Высокая"));
                    product[5]++;
                    
                        if ((f.textBox2.Text != null) && (f.textBox3.Text != null) || (f.textBox4.Text != null) || (f.textBox5.Text != null))
                        {
                            product[0]++;
                            product[1]++;

                            product[2]++;
                            product[3]++;

                            product[4]++;
                            product[5]++;
                            
                            productList1.Add(cr.FactoryMethod3(f.textBox2.Text, Decimal.Parse(f.textBox3.Text), 
                                Decimal.Parse(f.textBox4.Text), f.textBox5.Text, f.textBox6.Text, f.textBox7.Text));
                            
                            productList2.Add(cr.FactoryMethod4(f.textBox2.Text, Decimal.Parse(f.textBox3.Text),
                                Decimal.Parse(f.textBox4.Text), f.textBox5.Text, f.textBox6.Text, Decimal.Parse(f.textBox7.Text)));
                            
                            productList3.Add(cr.FactoryMethod5(f.textBox2.Text, Decimal.Parse(f.textBox3.Text),
                                Decimal.Parse(f.textBox4.Text), f.textBox5.Text, f.textBox6.Text, Decimal.Parse(f.textBox7.Text),
                                Decimal.Parse(f.textBox8.Text)));
                            
                            productList4.Add(cr.FactoryMethod7(f.textBox2.Text, Decimal.Parse(f.textBox3.Text),
                                Decimal.Parse(f.textBox4.Text), f.textBox5.Text, Decimal.Parse(f.textBox6.Text)));
                            
                            productList5.Add(cr.FactoryMethod8(f.textBox2.Text, Decimal.Parse(f.textBox3.Text),
                                Decimal.Parse(f.textBox4.Text), f.textBox5.Text, Decimal.Parse(f.textBox6.Text)));
                            
                            productList6.Add(cr.FactoryMethod9(f.textBox2.Text, Decimal.Parse(f.textBox3.Text),
                                Decimal.Parse(f.textBox4.Text), f.textBox5.Text)); 
                             

                           
                        }
                    }
                    catch (Exception ex)
                    {
                        FileLogger FileLogger = new FileLogger();
                        FileLogger.Log(ex.ToString());

                        ConsoleLoger ConsoleLoger = new ConsoleLoger();
                        ConsoleLoger.Log(ex.ToString());

                        MessageBox.Show(ex.Message);
                    }
                }

            }

            String[] strin0 = new string[product[0]];
            int it0 = 0;

            foreach (Cargo pr in productList1)
            {
                try
                {
                    if (it0 < product[0])
                    {
                        this.productList1 = new List<Cargo>();
                        strin0[it0] = null;
                        InformationBox.Text = "";
                        InformationBox.Clear();
                        strin0[it0] = ("Название самолета: " + pr.Name + "; \r\n" +
                                      "Количество двигателей: " + pr.Structure + "; \r\n" +
                                      "Количество человек: " + pr.Size + "; \r\n" +
                                      "Маневренность: " + pr.Maneuverability + "; \r\n" +
                                      "Мощь: " + pr.Power + "; \r\n" +
                                      "Степень защиты:  " + pr.Protection + "; \r\n");
                        it0++;
                        
                        CountPassengers[0] += (int)pr.Size;
                    }

                    if (comboBox1.SelectedIndex == -1)
                    {
                        InformationBox.Text = string.Empty;
                        Information2.Text = string.Empty;
                    }
                    else if (comboBox1.SelectedItem == "Cargos")
                    {

                        this.InformationBox.Text = String.Join(Environment.NewLine, strin0);
                        
                        string CountCargo = ("Количество человек в грузовых самолетах: " + CountPassengers[0]);
                        Information2.Text = CountCargo;

                    }
                }
                catch (Exception ex)
                {

                    FileLogger FileLogger = new FileLogger();
                    FileLogger.Log(ex.ToString());

                    ConsoleLoger ConsoleLoger = new ConsoleLoger();
                    ConsoleLoger.Log(ex.ToString());

                    MessageBox.Show(ex.Message);
                }
            }

            String[] strin1 = new string[product[1]];
            int it1 = 0;

            foreach (Agriculture pr in productList2)
            {
                try
                {
                    if (it1 < product[1])
                    {
                        this.productList2 = new List<Agriculture>();
                        strin1[it1] = ("Название самолета: " + pr.Name + "; \r\n" +
                                      "Количество двигателей: " + pr.Structure + "; \r\n" +
                                      "Количество человек: " + pr.Size + "; \r\n" +
                                      "Маневренность: " + pr.Maneuverability + "; \r\n" +
                                      "Мощь: " + pr.Power + "; \r\n" +
                                      "Стоимость: " + pr.Cost + "; \r\n");
                        it1++;
                        CountPassengers[1] += (int)pr.Size;
                    }

                    if (comboBox1.SelectedIndex == -1)
                    {
                        InformationBox.Text = string.Empty;
                        Information2.Text = string.Empty;
                    }
                    else if (comboBox1.SelectedItem == "Agricultures")
                    {
                        InformationBox.Text = String.Join(Environment.NewLine, strin1);
                        string CountAgriculture = ("Количество человек в сельскохозяйственных самолетах: " + CountPassengers[1]);
                        Information2.Text = CountAgriculture;
                    }
                }
                catch (Exception ex)
                {

                    FileLogger FileLogger = new FileLogger();
                    FileLogger.Log(ex.ToString());

                    ConsoleLoger ConsoleLoger = new ConsoleLoger();
                    ConsoleLoger.Log(ex.ToString());

                    MessageBox.Show(ex.Message);
                }
            }

            String[] strin2 = new string[product[2]];
            int it2 = 0;

            foreach (LightAircraft pr in productList3)
            {
                try
                {
                    if (it2 < product[2])
                    {
                        this.productList3 = new List<LightAircraft>();
                        strin2[it2] = ("Название самолета: " + pr.Name + "; \r\n" +
                                      "Количество двигателей: " + pr.Structure + "; \r\n" +
                                      "Количество человек: " + pr.Size + "; \r\n" +
                                      "Маневренность: " + pr.Maneuverability + "; \r\n" +
                                      "Мощь: " + pr.Power + "; \r\n" +
                                      "Вес: " + pr.Light + "; \r\n" +
                                      "Скорость: " + pr.Speed + "; \r\n");
                        it2++;
                        CountPassengers[2] += (int)pr.Size;
                    }

                    if (comboBox1.SelectedIndex == -1)
                    {
                        InformationBox.Text = string.Empty;
                        Information2.Text = string.Empty;
                    }
                    else if (comboBox1.SelectedItem == "LightAircrafts")
                    {
                        InformationBox.Text = String.Join(Environment.NewLine, strin2);
                        string CountLightAircraft = ("Количество человек в легких самолетах: " + CountPassengers[2]);
                        Information2.Text = CountLightAircraft;
                    }
                }
                catch (Exception ex)
                {

                    FileLogger FileLogger = new FileLogger();
                    FileLogger.Log(ex.ToString());

                    ConsoleLoger ConsoleLoger = new ConsoleLoger();
                    ConsoleLoger.Log(ex.ToString());

                    MessageBox.Show(ex.Message);
                }
            }

            String[] strin3 = new string[product[3]];
            int it3 = 0;

            foreach (Screw pr in productList4)
            {
                try
                {
                    if (it3 < product[3])
                    {
                        this.productList4 = new List<Screw>();
                        strin3[it3] = ("Название самолета: " + pr.Name + "; \r\n" +
                                      "Количество двигателей: " + pr.Structure + "; \r\n" +
                                      "Количество человек: " + pr.Size + "; \r\n" +
                                      "Вместимость: " + pr.Capacity + "; \r\n" +
                                      "Скорость: " + pr.Slow + "; \r\n");
                        it3++;
                        CountPassengers[3] += (int)pr.Size;
                    }

                    if (comboBox1.SelectedIndex == -1)
                    {
                        InformationBox.Text = string.Empty;
                        Information2.Text = string.Empty;
                    }
                    else if (comboBox1.SelectedItem == "Screws")
                    {
                        InformationBox.Text = String.Join(Environment.NewLine, strin3);
                        string CountScrew = ("Количество человек в винтовых самолетах: " + CountPassengers[3]);
                        Information2.Text = CountScrew;
                    }
                }
                catch (Exception ex)
                {

                    FileLogger FileLogger = new FileLogger();
                    FileLogger.Log(ex.ToString());

                    ConsoleLoger ConsoleLoger = new ConsoleLoger();
                    ConsoleLoger.Log(ex.ToString());

                    MessageBox.Show(ex.Message);
                }
            }

            String[] strin4 = new string[product[4]];
            int it4 = 0;

            foreach (Transcontinental pr in productList5)
            {

                try
                {

                    if (it4 < product[4])
                    {
                        this.productList5 = new List<Transcontinental>();
                        strin4[it4] = ("Название самолета: " + pr.Name + "; \r\n" +
                                      "Количество двигателей: " + pr.Structure + "; \r\n" +
                                      "Количество человек: " + pr.Size + "; \r\n" +
                                      "Вместимость: " + pr.Capacity + "; \r\n" +
                                      "Дальность полета: " + pr.Range + "; \r\n");
                        it4++;
                        CountPassengers[4] += (int)pr.Size;
                    }
                    if (comboBox1.SelectedIndex == -1)
                    {
                        InformationBox.Text = string.Empty;
                        Information2.Text = string.Empty;
                    }
                    else if (comboBox1.SelectedItem == "Transcontinentals")
                    {
                        InformationBox.Text = String.Join(Environment.NewLine, strin4);
                        string CountTranscontinental = ("Количество человек в трансконтинентальных самолетах: " + CountPassengers[4]);
                        Information2.Text = CountTranscontinental;
                    }
                }
                catch (Exception ex)
                {

                    FileLogger FileLogger = new FileLogger();
                    FileLogger.Log(ex.ToString());

                    ConsoleLoger ConsoleLoger = new ConsoleLoger();
                    ConsoleLoger.Log(ex.ToString());

                    MessageBox.Show(ex.Message);
                }
            }

            String[] strin5 = new string[product[5]];
            int it5 = 0;

            foreach (Personal pr in productList6)
            {

                try
                {
                    if (it5 < product[5])
                    {
                        this.productList6 = new List<Personal>();
                        strin5[it5] = ("Название самолета: " + pr.Name + "; \r\n" +
                                      "Количество двигателей: " + pr.Structure + "; \r\n" +
                                      "Количество человек: " + pr.Size + "; \r\n" +
                                      "Степень удобства: " + pr.Convenience + "; \r\n");
                        it5++;
                        CountPassengers[5] += (int)pr.Size;
                    }
                    if (comboBox1.SelectedIndex == -1)
                    {
                        InformationBox.Text = string.Empty;
                        Information2.Text = string.Empty;
                    }
                    else if (comboBox1.SelectedItem == "Personals")
                    {
                        InformationBox.Text = String.Join(Environment.NewLine, strin5);
                        string CountPersonal = ("Количество человек в личных самолетах: " + CountPassengers[5]);
                        Information2.Text = CountPersonal;
                    }
                }
                catch (Exception ex)
                {

                    FileLogger FileLogger = new FileLogger();
                    FileLogger.Log(ex.ToString());

                    ConsoleLoger ConsoleLoger = new ConsoleLoger();
                    ConsoleLoger.Log(ex.ToString());

                    MessageBox.Show(ex.Message);
                }
            }


        }

        private void InformationBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Information2_TextChanged(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void AddPlane_Click(object sender, EventArgs e)
        {
            f.Show(); // показываем
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            InformationBox.Text = "";
            InformationBox.Clear();

            foreach (Creator cr in creators)
            {
                if (cr is CreatorService)
                {
                    this.productList1 = new List<Cargo>();
                    this.productList2 = new List<Agriculture>();
                    this.productList3 = new List<LightAircraft>();
                    this.productList4 = new List<Screw>();
                    this.productList5 = new List<Transcontinental>();
                    this.productList6 = new List<Personal>();
                    this.CountPassengers = new int[10];
                    for (int i = 0; i < 7; i++)
                    {
                        //CountPassengers.Add(0);
                        CountPassengers[i] = 0;
                    }

                    if (comboBox1.SelectedItem == "Cargos")
                    {
                       
                        string CountPersonal = ("Количество человек в грузовых самолетах: " + CountPassengers[5]);
                        Information2.Text = CountPersonal;
                    }
                    if (comboBox1.SelectedItem == "Agricultures")
                    {

                        string CountPersonal = ("Количество человек в сельскохозяйственных самолетах: " + CountPassengers[5]);
                        Information2.Text = CountPersonal;
                    }
                    if (comboBox1.SelectedItem == "LightAircrafts")
                    {

                        string CountPersonal = ("Количество человек в легких самолетах: : " + CountPassengers[5]);
                        Information2.Text = CountPersonal;
                    }
                    if (comboBox1.SelectedItem == "Screws")
                    {

                        string CountPersonal = ("Количество человек в винтовых самолетах: " + CountPassengers[5]);
                        Information2.Text = CountPersonal;
                    }
                    if (comboBox1.SelectedItem == "Transcontinentals")
                    {

                        string CountPersonal = ("Количество человек в трансконтинентальных самолетах: " + CountPassengers[5]);
                        Information2.Text = CountPersonal;
                    }
                    if (comboBox1.SelectedItem == "Personals")
                    {

                        string CountPersonal = ("Количество человек в личных самолетах: " + CountPassengers[5]);
                        Information2.Text = CountPersonal;
                    }
                }
            }
        }

        private void DeletePlane_Click(object sender, EventArgs e)
        { 
            f.textBox2.Text = null;
            f.textBox3.Text = null; 
            f.textBox4.Text = null;
            f.textBox5.Text = null; 
            f.textBox6.Text = null;
            f.textBox7.Text = null; 
        }
    }
}

